//global

//config
require.config({
    baseUrl: "",
    waitSeconds: 15,//超时时间
    paths: {
        "jquery": "component/js/jquery.min",
        "text": "component/js/text",
        "handlebars": "component/js/handlebars",
        "init_index": "component/init/index",
        "slider": "component/init/slider",
    },
    shim: {
        'BMap': {
            deps: ['jquery'],
            exports: 'BMap'
        }
    }
});
// init
require(["jquery","handlebars","text"], function ($,handlebars,_){
    //网络请求
    var _request = function(type,url,data,cb,param){
        $.ajax({
            async: true,
            url: url,
            data: data,
            type: type,
            dataType: "json",
            beforeSend: function () {
                if(typeof param == "object" && param.beforeSend ){
                    param.beforeSend();
                }
            },
            complete: function () {
                if(typeof param == "object" && param.complete ){
                    param.complete();
                }
            },
            success: function (d, e, f) {
                cb(d);
            },
            error: function (xhr, textStatus, errorThrown) {
                if(typeof param == "object" && param.error ){
                    param.error();
                }else{
                    setTimeout(function (){
                        //history.back(-1);
                    },1000 )
                }
            }
        });
    };
    var init = function(){
        require(['init_index'],function(init_index){
            init_index.run();
        });
    };

    window.ADU={};
    ADU.tpl=function(source,context){
        //预编译模板
        var template = handlebars.compile(source);
        //匹配json内容
        var html = template(context);
        return html;
    };
    ADU.url = function(url){
       return adu_site+"/"+url;
    };
    ADU.post = function(url,data,cb,param){
        _request("POST",url,data,cb,param);
    };
    ADU.get = function(url,data,cb,param){
        _request("GET",url,data,cb,param);
    };
    (init)(window);
});
